package gudao.red.protobuf;

import gudao.red.protobuf.PersonFactory.Person;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	public static void main(String[] args) throws IOException {
		
		ServerSocket server = new ServerSocket(3030);
		while(true){
			Socket sock = server.accept();
			byte[] msg = new byte[256];
			sock.getInputStream().read(msg);
			
			int msgBodyLen = msg[0];
            System.out.println("msg body len:"+msgBodyLen);
            
            byte[] msgbody = new byte[msgBodyLen];
            System.arraycopy(msg, 1, msgbody, 0, msgBodyLen);
            
            Person person = Person.parseFrom(msgbody);
            System.out.println("Receive:");
            System.out.println(person);
		}

	}

}
